package com.zshan.clinic.web.controller.stat;


import com.zshan.clinic.admin.entity.vo.*;
import com.zshan.clinic.admin.service.stat.ClinicIncomeDailyService;
import com.zshan.clinic.admin.service.stat.ClinicPerformanceService;
import com.zshan.clinic.common.enums.ProjectCategoryEnum;
import com.zshan.clinic.common.response.RestResp;
import com.zshan.clinic.common.util.page.PageInfo;
import com.zshan.clinic.web.controller.AbstractController;
import com.zshan.clinic.web.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;


/**
 * 统计
 * @author lichen
 */
@RestController
@RequestMapping("/clinic/stat")
public class ClinicStatController extends AbstractController {

    @Autowired
    private ClinicIncomeDailyService clinicIncomeDailyService;

    @Autowired
    private ClinicPerformanceService clinicPerformanceService;

    /**
     * 业绩统计的入口
     * @param statDateVo
     * @return
     */
    @PostMapping("/clinicPerformanceStat")
    public RestResp<Void> clinicPerformanceStat(@RequestBody StatDateVo statDateVo) {
        clinicPerformanceService.clinicPerformanceStat(statDateVo.getStatDate());
        return RestResp.SUCCESS();
    }

    /**
     * 统计：业绩统计-挂号统计
     * @param empId 员工ID
     * @param startDate 开始时间 YYYY-MM-DD
     * @param endDate 结束时间 YYYY-MM-DD
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getEmpRegDailyList")
    public RestResp<PageInfo<StatClinicRegDailyVo>> getEmpRegDailyList(@RequestParam(name = "empId",required = false) Long empId,
                                                                       @RequestParam(name = "deptId",required = false) Long deptId,
                                                                       @RequestParam(name = "startDate",required = false) LocalDate startDate,
                                                                       @RequestParam(name = "endDate",required = false) LocalDate endDate,
                                                                       @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                                       @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        UserInfo userInfo = getUserInfo();
        PageInfo<StatClinicRegDailyVo> pageInfo = clinicPerformanceService.getEmpRegDailyList(userInfo.getClinicId(), empId,deptId,startDate,endDate,pageNo,pageSize);
        return RestResp.SUCCESS(pageInfo);
    }


    /**
     * 统计：业绩统计-收费统计
     * @param empId 员工ID
     * @param startDate 开始时间 YYYY-MM-DD
     * @param endDate 结束时间 YYYY-MM-DD
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getEmpChargeDailyList")
    public RestResp<PageInfo<StatClinicChargeDailyVo>> getEmpChargeDailyList(@RequestParam(name = "empId",required = false) Long empId,
                                                                             @RequestParam(name = "deptId",required = false) Long deptId,
                                                                             @RequestParam(name = "startDate",required = false) LocalDate startDate,
                                                                             @RequestParam(name = "endDate",required = false) LocalDate endDate,
                                                                             @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                                             @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        UserInfo userInfo = getUserInfo();
        PageInfo<StatClinicChargeDailyVo> pageInfo = clinicPerformanceService.getEmpChargeDailyList(userInfo.getClinicId(), empId,deptId,startDate,endDate,pageNo,pageSize);
        return RestResp.SUCCESS(pageInfo);
    }

    /**
     * 统计：业绩统计-门诊统计
     * @param empId 员工ID
     * @param startDate 开始时间 YYYY-MM-DD
     * @param endDate 结束时间 YYYY-MM-DD
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getEmpMedicalDailyList")
    public RestResp<PageInfo<StatClinicMedicalDailyVo>> getEmpMedicalDailyList(@RequestParam(name = "empId",required = false) Long empId,
                                                                               @RequestParam(name = "deptId",required = false) Long deptId,
                                                                              @RequestParam(name = "startDate",required = false) LocalDate startDate,
                                                                              @RequestParam(name = "endDate",required = false) LocalDate endDate,
                                                                              @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                                              @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        UserInfo userInfo = getUserInfo();
        PageInfo<StatClinicMedicalDailyVo> pageInfo = clinicPerformanceService.getEmpMedicalDailyList(userInfo.getClinicId(), empId,deptId,startDate,endDate,pageNo,pageSize);
        return RestResp.SUCCESS(pageInfo);
    }

    /**
     * 统计：业绩统计-检查统计/检验统计/执行统计
     * @param projectCategory 项目分类 projectCategoryEnum
     * @param empId 员工ID
     * @param startDate 开始时间 YYYY-MM-DD
     * @param endDate 结束时间 YYYY-MM-DD
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getEmpExamDailyList")
    public RestResp<PageInfo<StatClinicExamDailyVo>> getEmpExamDailyList(@RequestParam(name = "projectCategory") String projectCategory,
                                                                         @RequestParam(name = "empId",required = false) Long empId,
                                                                         @RequestParam(name = "deptId",required = false) Long deptId,
                                                                         @RequestParam(name = "startDate",required = false) LocalDate startDate,
                                                                         @RequestParam(name = "endDate",required = false) LocalDate endDate,
                                                                         @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                                         @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        UserInfo userInfo = getUserInfo();
        PageInfo<StatClinicExamDailyVo> pageInfo = clinicPerformanceService.getEmpExamDailyList(projectCategory,userInfo.getClinicId(),empId,deptId,startDate,endDate,pageNo,pageSize);
        return RestResp.SUCCESS(pageInfo);
    }

    /**
     * 统计：业绩统计-药房统计
     * @param empId 员工ID
     * @param startDate 开始时间 YYYY-MM-DD
     * @param endDate 结束时间 YYYY-MM-DD
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getEmpDispenseDailyList")
    public RestResp<PageInfo<StatClinicDispenseDailyVo>> getEmpDispenseDailyList(@RequestParam(name = "empId",required = false) Long empId,
                                                                                 @RequestParam(name = "deptId",required = false) Long deptId,
                                                                                 @RequestParam(name = "startDate",required = false) LocalDate startDate,
                                                                                 @RequestParam(name = "endDate",required = false) LocalDate endDate,
                                                                                 @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                                                 @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        UserInfo userInfo = getUserInfo();
        PageInfo<StatClinicDispenseDailyVo> pageInfo = clinicPerformanceService.getEmpDispenseDailyList(userInfo.getClinicId(), empId,deptId,startDate,endDate,pageNo,pageSize);
        return RestResp.SUCCESS(pageInfo);
    }

    /**
     * 统计：营收统计
     * @param startDate 开始时间 YYYY-MM-DD
     * @param endDate 结束时间 YYYY-MM-DD
     * @return
     */
    @GetMapping("/getClinicIncome")
    public RestResp<StatClinicIncomeDailyVo> getClinicIncome(@RequestParam(name = "startDate") LocalDate startDate,
                                                             @RequestParam(name = "endDate") LocalDate endDate) {
        UserInfo userInfo = getUserInfo();
        StatClinicIncomeDailyVo statClinicIncomeDailyVo = clinicIncomeDailyService.getClinicIncome(userInfo.getClinicId(), startDate,endDate);
        return RestResp.SUCCESS(statClinicIncomeDailyVo);
    }

}
